<?php
/**
 * Created by PhpStorm.
 * User: lixiaohui
 * Date: 2015/9/22
 * Time: 19:14
 */

namespace Home\Controller;


use Think\Controller;

/**
 * Class ServiceController
 * @package Home\Controller面向用户的服务
 */
class ServiceController extends Controller
{
    //用户用水查询
    public function usedSearch()
    {
        $openId = getOpenId();
        $relevanceModel = M('member_relevance')->where("openid='%s'", $openId)->field('id,userid')->select();
        $this->assign("relevanceModel", $relevanceModel);
        $this->assign("bottomMenu", getBottomMenu());
        $this->display();
    }

    //用水查询结果
    public function usedSearchResult()
    {
        $userid = I('userid');
        $year = I('year');
        $args = array(
            "userid" => $userid,
            "queryyear" => $year
        );
        //调用接口进行用水查询
        $retObj = doQuery('QueryUserWaterLog', $args);
        $this->assign("json", $retObj);
        $this->display();
    }
    //缴费查询
    public function feeSearch(){
        $openId = getOpenId();
        $relevanceModel = M('member_relevance')->where("openid='%s'", $openId)->field('id,userid')->select();
        $this->assign("relevanceModel", $relevanceModel);
        $this->assign("bottomMenu", getBottomMenu());
        $this->display();
    }
    //缴费查询结果
    public function feeSearchResult(){
        $userid = I('userid');
        $year = I('year');
        $args = array(
            "userid" => $userid,
            "queryyear" => $year
        );
        //判断用户是否存在
        if (!isUserExist(1, $userid)) {
            $retObj = array(
                "retcode" => -1,
                "msg" => "用户 '$userid' 不存在",
                "userid" => $userid,
                "year" => $year
            );
            $this->assign("json", $retObj);
            $this->display();
            return;
        }
        //调用接口进行缴费查询
        $retObj = doQuery('QueryRechargeLog', $args);
        $this->assign("json", $retObj);
        $this->display();
    }

    //预存查询
    public function preSaveSearch(){
        $openId = getOpenId();
        $relevanceModel = M('member_relevance')->where("openid='%s'", $openId)->field('id,userid')->select();
        $this->assign("relevanceModel", $relevanceModel);
        $this->assign("bottomMenu", getBottomMenu());
        $this->display();
    }
    //预存查询结果
    public function preSaveSearchResult(){
        $userid = I('userid');
        $year = I('year');
        $args = array(
            "userid" => $userid,
            "queryyear" => $year
        );
        //判断用户是否存在
        if (!isUserExist(1, $userid)) {
            $retObj = array(
                "retcode" => -1,
                "msg" => "用户 '$userid' 不存在",
                "userid" => $userid,
                "year" => $year
            );
            $this->assign("json", $retObj);
            $this->display();
            return;
        }
        //调用接口进行预存查询
        $retObj = doQuery('QueryAccount', $args);
        $this->assign("json", $retObj);
        $this->display();
    }
}